package com.lonton.controller;

import java.util.List;

import redis.clients.jedis.Jedis;

public class RedisTest {
	private static Jedis jedis = null;
	public static void main(String[] args) {
		try {
			//连接本地的 Redis 服务
	        jedis = new Jedis("localhost");
	        jedis.auth("zpj520wwf");
	        System.out.println("连接成功");
	        
	        //存储数据到列表中
	        jedis.lpush("site-list", "Runoob");
	        jedis.lpush("site-list", "Google");
	        jedis.lpush("site-list", "Taobao");
	        System.out.println(jedis.get("author")+"-------"+jedis.get("name"));
	        // 获取存储的数据并输出
	        List<String> list = jedis.lrange("site-list", 0 ,2);
	        for(int i=0; i<list.size(); i++) {
	            System.out.println("列表项为: "+list.get(i));
	        }
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			if (jedis!=null) {
				jedis.close();
			}
		}
	}
}

